package com.qy33.entity;

import java.math.BigDecimal;

import com.qy33.util.AmountUtil;


/**
 * 高低点的连线实体
 * @author Henry
 * @date 2013-1-25
 */
public class Line {
	
	// 1是向上的线段，2是向下的线段
	public static final int Type_Up = 1;
	public static final int Type_Down = 2;

	private String code;
	private Dot begin;
	private Dot end;
	private int type;
	
	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer(64);
		sb.append("[code=").append(code)
		.append(", range=").append(getRange())
		.append(", begin=").append(begin)
		.append(", end=").append(end).append(", type=").append(type).append("]");
		return sb.toString();
	}
	
	@Override
	public boolean equals(Object obj) {
		Line to = (Line) obj;
		if (code.equals(to.getCode()) 
			&& begin.equals(to.getBegin())
			&& end.equals(to.getEnd())
			&& type == to.getType()) {
			return true;
		}
		return false;
	}
	
	// 后面一点对低点的幅度
	public BigDecimal getRange() {
		if (begin == null || end == null) {
			return null;
		}
		// 向上的线段，表示涨幅；向下的线段，表示跌幅
		return AmountUtil.divide(AmountUtil.subtract(end.getPrice(), begin.getPrice()), begin.getPrice());
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public Dot getBegin() {
		return begin;
	}

	public void setBegin(Dot begin) {
		this.begin = begin;
	}

	public Dot getEnd() {
		return end;
	}

	public void setEnd(Dot end) {
		this.end = end;
	}
	
}
